﻿using System.Data.Common;
using System.Data.Entity;
using Abp.EntityFramework;
using LpbPrj.Client.EntityMapper;
using LpbPrj.Client.Options;
using LpbPrj.Client.Patients;
using LpbPrj.Client.Records;
using LpbPrj.Client.Reports;
using LpbPrj.Client.Results;
using LpbPrj.Client.Users;

namespace LpbPrj.Client.EntityFramework
{
    public class ClientDbContext : AbpDbContext
    {
        //TODO: Define an IDbSet for each Entity...

        //Example:
        public virtual IDbSet<Patient> Patients { get; set; }
        public virtual IDbSet<Record> Records { get; set; }
        public virtual IDbSet<CornealTopoGraphy> CornealTopoGraphy { get; set; }
        public virtual IDbSet<Report> Reports { get; set; }

        public virtual IDbSet<Option> Options { get; set; }
        public virtual IDbSet<User> Users { get; set; }

        /* NOTE: 
         *   Setting "Default" to base class helps us when working migration commands on Package Manager Console.
         *   But it may cause problems when working Migrate.exe of EF. If you will apply migrations on command line, do not
         *   pass connection string name to base classes. ABP works either way.
         */
        public ClientDbContext()
            : base("Default")
        {

        }

        /* NOTE:
         *   This constructor is used by ABP to pass connection string defined in ClientDataModule.PreInitialize.
         *   Notice that, actually you will not directly create an instance of ClientDbContext since ABP automatically handles it.
         */
        public ClientDbContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {

        }

        //This constructor is used in tests
        public ClientDbContext(DbConnection existingConnection)
         : base(existingConnection, false)
        {

        }

        public ClientDbContext(DbConnection existingConnection, bool contextOwnsConnection)
         : base(existingConnection, contextOwnsConnection)
        {

        }


        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Configurations.Add(new PatientInfoCfg()); 
            modelBuilder.Configurations.Add(new RecordCfg());
            modelBuilder.Configurations.Add(new CornealTopoGraphyCfg());
            modelBuilder.Configurations.Add(new ReportPageCfg());

            modelBuilder.Configurations.Add(new OptionInfoCfg());
            modelBuilder.Configurations.Add(new UserInfoCfg());
        }
    }
}
